package 力扣._108_将有序数组转换为二叉搜索树;

import 力扣.公用数据结构.TreeNode;

public class Solution {

    //
    TreeNode creatAVL(int[] nums, int l, int r) {
        if (l == r)
            return new TreeNode(nums[l]);
        else if (l > r)
            return null;
        int mid = (l + r) / 2;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = creatAVL(nums, l, mid - 1);
        node.right = creatAVL(nums, mid + 1, r);
        return node;

    }

    public TreeNode sortedArrayToBST(int[] nums) {
        return creatAVL(nums, 0, nums.length - 1);
    }
}
